package com.tzbank.wisdom.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.tzbank.entity.Theme;
import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.HttpUtil;
import com.tzbank.utils.ResultUtil;
import com.tzbank.wisdom.dao.BusinessMapper;
import com.tzbank.wisdom.entity.dto.BusinessFieldsDTO;
import com.tzbank.wisdom.service.BusinessService;
import com.tzbank.wisdom.service.FinanceService;
import com.tzbank.wisdom.service.SaveService;


@Service(value = "businessService")
public class BusinessServiceImpl implements BusinessService {

	@Autowired
    private BusinessMapper businessMapper;
	
	@Autowired
	private SaveService saveService;
	@Autowired
	private FinanceService financeService;
	
	@Autowired
    RestTemplate restTemplate;
	
	/**
	 * 根据科大讯飞主题获得主题id
	 */
	public Theme selectThemeByIflytek(String iflytekFieldsId) {
		return businessMapper.selectThemeByIflytek(iflytekFieldsId);
	}
	
	/**
	 * 根据业务id获得业务元素和科大字段映射集合
	 */
	public List<BusinessFieldsDTO> selectBusinessIflytekListByid(String businessId){
    	return businessMapper.selectBusinessIflytekListByid(businessId);
    }
	
	/**
	 * 主题公共方法
	 */
    public Map<String,Object> theme(Map<String,String> reqBody) {
    	String themeId = reqBody.get("themeId");		//主题id
    	//主题ID判断
    	if(StringUtils.isBlank(themeId)) {
    		 return ResultUtil.resultMap(CodeUtil.CODE_10000.getName(), CodeUtil.CODE_10000.getCode(), reqBody);
    	}
    	
    	return getPageflow(reqBody);			//获取主题页面流程
    }
	
	/**
	 * 获取主题页面流程
	 */
    public Map<String,Object> getPageflow(Object model) {
    	String url = "http://framework-common-service/common/theme";
    	HttpEntity<String> entity = HttpUtil.createHttpEntity(model);		//获取spring web的消息实体
 		return restTemplate.postForObject(url, entity, Map.class);		
    }
    
    @Override
    public Map<String, Object> transferSelectContacts(Object model) {
    	String url = "http://framework-common-service/queryContactsByUserIdAndName";
    	HttpEntity<String> entity = HttpUtil.createHttpEntity(model);		//获取spring web的消息实体
 		return restTemplate.postForObject(url, entity, Map.class);	
    }
    
}
